Lines

library(dplyr)
library(echarts4r.assets)

# download
flights <- jsonlite::fromJSON("https://ecomfe.github.io/echarts-examples/public/data-gl/asset/data/flights.json")

# airports
airports <- as.data.frame(flights$airports)
names(airports) <- flights$airportsFields

airports <- airports %>% 
  select(name, longitude, latitude) %>% 
  tibble::rownames_to_column("ID") %>% 
  mutate(ID = as.integer(paste0(ID)))

# routes
routes <- as.data.frame(flights$routes)
names(routes) <- c("ID", "from", "to")

# airlines
airlines <- as.data.frame(flights$airlines) %>% 
  tibble::rownames_to_column("ID") %>% 
  mutate(ID = as.integer(paste(ID))) %>% 
  select(ID, airline = V1, country = V2)

# bind
data <- routes %>% 
  inner_join(airports, by = c("from" = "ID")) %>% 
  inner_join(airports, by = c("to" = "ID"), suffix = c(".start", ".end")) %>%
  inner_join(airlines, by = "ID") %>% 
  select(airline, longitude.start, latitude.start, longitude.end, latitude.end) 

# initialise plot  
data %>%
  group_by(airline) %>% 
  e_charts() %>% 
  e_globe(
    base_texture = ea_asset("world dark"),
    environment = ea_asset("starfield"),
    displacementScale = 0.1,
    displacementQuality = "high",
    shading = "realistic",
    realisticMaterial = list(
      roughness = .2,
      metalness = 0
    ),
    postEffect = list(
      enable = TRUE,
      depthOfField = list(
        enable = FALSE
      )
    ),
    temporalSuperSampling = list(
      enable = TRUE
    ),
    light = list(
      ambient = list(
        intensity = 1
      ),
      main = list(
        intensity = .1,
        shadow = FALSE
      )
    ),
    viewControl = list(autoRotate = FALSE)
  ) %>% 
  e_legend(
    selectedMode = "single", 
    left = "left",
    textStyle = list(color = "#fff"),
    orient = "vertical"
  ) %>% 
  e_lines_3d(
    longitude.start, latitude.start, longitude.end, latitude.end, 
    coord_system = "globe", 
    effect = list(
      show = TRUE,
      trailWidth = 2,
      trailLength = 0.15,
      trailOpacity = 1,
      trailColor = 'rgb(30, 30, 60)'
    ),
    lineStyle = list(opacity = 0.1, widh = 0.5, color = 'rgb(50, 50, 150)')
  )

Scatter 3D

Timeline

This is a temporary implementation of the timeline component, it will, eventually, be properly incorporated into the package.

aggregate <- OrchardSprays %>% 
    group_by(treatment, colpos) %>% 
    summarise(
        decrease = sum(decrease)
    ) %>% 
    group_by(treatment)

OrchardSprays %>% 
    group_by(treatment) %>% 
    e_charts(rowpos, timeline = TRUE) %>% 
    e_line(decrease) %>% 
    e_data(aggregate, colpos) %>% 
    e_pie(
      decrease, 
      center = list("75%", "35%"),
      radius = "20%",
      rm_x = FALSE, 
      rm_y = FALSE
    ) %>% 
  e_timeline_opts(autoPlay = TRUE)